function shellSort (arr) {
  let len = arr.length
  // gap 即为增量
  for (let gap = Math.floor(len / 2); gap > 0; gap = Math.floor(gap / 2)) {
    for (let i = gap; i < len; i++) {
      let j = i
      let current = arr[i]
      while (j - gap >= 0 && current < arr[j - gap]) {
        arr[j] = arr[j - gap]
        j = j - gap
      }
      arr[j] = current
    }
  }
  return arr
}

// let shellSort = function () {
//   //获取数组长度
//   var size = this.items.length
//   //初始化增量(间隔)
//   var gap = Math.floor(size / 2)
//   while (gap >= 1) {
//     //gap分组，分组进行排序
//     for (var i = gap; i < size; i++) {
//       var temp = this.items[i]
//       var j = i
//       while (this.items[j - gap] > temp & j > gap - 1) {
//         this.items[j] = this.items[j - gap]
//         j -= gap
//       }
//       this.items[j] = temp
//     }
//     gap = Math.floor(gap / 2)
//   }
// }


var arr = [3, 5, 7, 1, 4, 56, 12, 78, 25, 0, 9, 8, 42, 37]
console.log(shellSort(arr))